<?php
class click extends spController
{
	function go()
	{
		$pid = intval($_GET['pid']);
		if($pid < 1) return false;
		$m_youhui = spClass("youhui");
		$result = $m_youhui->find(array('pid'=>$pid), '', 'url');
		if(!$result) return false;
		$m_click = spClass("m_click");

		$sql = "UPDATE youhui SET nums=nums+1 WHERE pid='$pid'";
		$m_youhui->runSql($sql);	
		if(!empty($_SESSION['visitor_id']) && !empty($_SESSION['visitor_nick'])) {
			$m_click->create(array('pid'=>$pid, 'visitor_id'=>$_SESSION['visitor_id'], 'visitor_nick'=>$_SESSION['visitor_nick'], 'clicktime'=>date('Y-m-d H:i:s', time()), 'ip'=>ip()));
		} elseif($pid) {
			$m_click->create(array('pid'=>$pid, 'visitor_id'=>0, 'visitor_nick'=>0, 'clicktime'=>date('Y-m-d H:i:s', time()), 'ip'=>ip()));
		}
		header('location:' . $result['url'], 301);
		exit;
	}

	function w_go()
	{
		$wid = intval($_GET['wid']);
		if($wid < 1) return false;
		$m_weibo = spClass('m_weibo');
		
		$result = $m_weibo->find(array('w_id'=>$wid));
		if(!$result) return false;
		$sql = "UPDATE w_youhui SET nums=nums+1 WHERE w_id='$wid'";
		$m_weibo->runSql($sql);
		$m_wclick = spClass('m_wclick');
		if(!empty($_SESSION['visitor_id']) && !empty($_SESSION['visitor_nick'])) {
			$m_wclick->create(array('w_id'=>$wid, 'visitor_id'=>$_SESSION['visitor_id'], 'visitor_nick'=>$_SESSION['visitor_nick'], 'clicktime'=>date('Y-m-d H:i:s', time())));
		} elseif($wid) {
			$m_wclick->create(array('w_id'=>$wid, 'visitor_id'=>0, 'visitor_nick'=>0, 'clicktime'=>date('Y-m-d H:i:s', time())));
		}
		header('location:' . $result['url'], 301);
		exit;
	}
}